package mysqloperate;

import people.User;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class checkuser {
    User use=null;
    public checkuser(){

    }
    public checkuser(User use){
        this.use=use;
    }
    public boolean check() throws Exception {
        boolean bb=false;
        String sql="select * from user";
        connection con=new connection();
        Connection connection=con.getconnection();
        Statement statement=connection.createStatement();
        ResultSet rest=statement.executeQuery(sql);

        int count=0;
        while (rest.next()){
            count++;
        }
        String str[][]=new String[count][2];
        rest=statement.executeQuery(sql);
        count=0;
        while (rest.next()) {
            str[count][0]=rest.getString("zhanghao");
            str[count][1]=rest.getString("password");
            count++;
        }

        for (int i=0;i<str.length;i++){
            if(use.getId().equals(str[i][0])) {
                if(use.getPassword().equals(str[i][1])){
                    bb=true;
              }
            }else continue;

        }
        rest.close();
        statement.close();
        connection.close();
        return bb;
    }

}
